package com.xinfan.tank;

/**
 * @Author xin
 * @Date 2022/6/5 21:04
 * @Version 1.0
 */
public class Bullet implements Runnable {

    int x;
    int y;
    int speed = 2;
    int direction;
    Boolean isAlive = true;

    public Bullet(int x, int y, int direction) {
        this.x = x;
        this.y = y;
        this.direction = direction;
    }


    /*public void shot() {
        switch (direction) {
            case 1:
                x++;
                break;
            case 3:
                x--;
                break;
            case 2:
                y++;
                break;
            case 0:
                y--;
                break;
        }
    }
*/

    @Override
    public void run() {
        while (true) {

            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            switch (direction) {
                case 0:
                    y -= speed;
                    break;
                case 1:
                    x += speed;
                    break;
                case 2:
                    y += speed;
                    break;
                case 3:
                    x -= speed;
                    break;
            }

            //System.out.println("X:" + x + "y:" + y);

            if (!(x >= 0 && x <= 1000 && y >= 0 && y <= 750 && isAlive)) {
                isAlive = false;
                System.out.println("子弹撞墙");
                return;
            }



        }


    }
}
